import { legacy_createStore as createStore,applyMiddleware } from '../redux';
import rootReducer from './reducers';
import logger  from './redux-logger';
import thunk  from './redux-thunk';
import promise from './redux-promise';
const store = applyMiddleware(promise,thunk,logger)(createStore)(rootReducer);
export default store;

//实现一个日志中间件，就是在状态变更的前后打印变更前的状态和变更后的状态
//中间的核心原理是通过改造store.dispatch实现的
//缓存旧的或者说原始的dispatch函数
/*
let next = store.dispatch;
store.dispatch = function(action){
    console.log('prev state',store.getState())
    next(action);//调用原生的dispatch
    console.log('after state',store.getState())
} 
store.dispatch = function(action){
   setTimeout(()=>{
    next(action);//调用原生的dispatch
   },1000);
}
*/